package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.mapper.GeofenceMapper;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceSaveParam;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="电子围栏模块")
@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    GeofenceService geofenceService;

    @GetMapping("select")
    @Operation(summary = "查询电子围栏")
    @ApiOperationSupport(order = 10)
    public JsonResult select(GeofenceQuery query){
        log.debug("查询电子围栏："+query);
        List<GeofenceVO> list= geofenceService.selectGeofence(query);
        return JsonResult.ok(list);
    }

    @PostMapping("update/{id}/{status}")
    @Operation(summary = "更新电子围栏")
    @ApiOperationSupport(order = 20)
    public JsonResult update(@PathVariable Long id,@PathVariable String status){
        log.debug("更新电子围栏："+id+"--"+status);
        geofenceService.updateGeofence(id, status);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    @Operation(summary = "删除电子围栏")
    @ApiOperationSupport(order = 30)
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除电子围栏："+id);
        geofenceService.deleteGeofenceId(id);
        return JsonResult.ok();
    }


    @PostMapping("save")
    @Operation(summary = "新增电子围栏")
    @ApiOperationSupport(order = 40)
    public JsonResult saveGeo(GeofenceSaveParam param){
        log.debug("新增电子围栏："+param);
        geofenceService.saveGeofence(param);
        return JsonResult.ok();
    }


}
